package java学习.JUC.Callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * **************
 * 项目名称: 蓝桥杯 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/6/3 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
class Th1 implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"进入run");
    }
}
class Th2 implements Callable{

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"进入call");
        return 100;
    }
}

public class test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Th1 th1 = new Th1();
        FutureTask<Integer> task = new FutureTask<Integer>(new Th2());
        new Thread(task,"B").start();
        System.out.println(task.get());

        new Thread(th1,"A").start();

        FutureTask<Integer> task1 = new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return null;
            }
        });
        FutureTask task2 = new FutureTask<>(()->{
            System.out.println(Thread.currentThread().getName()+"进入run");
            return null;
        });

        ThreadGroup group = new ThreadGroup("线程组1");
        Thread[] threads = new Thread[group.activeCount()];
        group.enumerate(threads);
    }
}
